<template>
    <div class="cartcontrol">
        <transition name="move">
            <div class="cart_decrease" v-show="food.count>0" @click.stop.prevent="min($event)">-</div>
        </transition>
        <div class="cart_count" v-show="food.count>0">{{food.count}}</div>
        <div class="cart_add" @click.stop.prevent="add($event)">+</div>
    </div>
</template>

<script>
import Vue from 'vue';
export default {
    props: {
        food: {
            type: Object
        }
    },
    created() {
        //console.log(this.food)
    },
    data() {
        return {}
    },
    methods: {
        add(e) {
            if (e._constructed) {
                if (!this.food.count) {
                    Vue.set(this.food, 'count', 1);
                } else {
                    this.food.count++;
                }
                this.$emit('add', event.target);
            }
        },
        min(e) {
            if (e._constructed) {
                if (this.food.count > 0) {
                    this.food.count--;
                }
            }
        },
    }
};
</script>

<style scoped>
.cartcontrol {
    font-size: 0;
}

.cart_decrease,
.cart_add {
    display: inline-block;
    padding: 6px;
    font-size: 15px;
    line-height: 10px;
    height: 12px;
    width: 12px;
    text-align: center;
    background: rgb(0, 160, 220);
    color: #fff;
    border-radius: 50%;
}
.cart_add{
    transition: all 0.4s linear;
    transform: rotate(0)
}
.move-enter-active, .move-leave-active{
    transition: all 0.2s linear
}
.move-enter, .move-leave-active{
    opacity: 0;
    transform: translate3d(24px, 0, 0)
}
.cart_count {
    display: inline-block;
    font-size: 14px;
    padding: 0 5px;
}
</style>
